Added wave sort a new sorting technique #11538
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Wave Sort Algorithm
Wave Sort is a novel sorting algorithm designed to sort an array by creating a wave-like pattern. The algorithm divides the array into two halves recursively, sorts each half, and then merges them in a way that alternates between larger and smaller elements, creating a wave-like structure.
How It Works:
Divide: The array is recursively divided into two halves.
Sort: Each half is sorted individually.
Wave Shuffle: The sorted halves are then merged in a wave pattern by alternating elements from the left and right halves.
Wave Merge: The algorithm ensures that the final array follows a wave pattern where each element alternates between being greater and less than its neighboring elements.
Final Sorting Pass: A final insertion sort pass ensures that the wave structure is maintained while sorting the array.
Time Complexity:
The worst-case time complexity of the Wave Sort algorithm is 𝑂(𝑛2)
However, due to the wave merging process, the algorithm can perform better on nearly sorted arrays.
Space Complexity:
The space complexity is 𝑂(𝑛)
O(n) due to the additional space required for the auxiliary array and the recursion stack.
Applications:
Wave Sort can be useful in scenarios where a specific wave-like pattern is desired in the sorted data, such as in certain data visualizations or specialized sorting tasks.